<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Company extends Model
{
	
    protected $table = 'company';
    public $timestamps = false;


    /**
     * 查询结果时 被隐藏的属性
     *
     * @var array
     */
    protected $hidden = [
        'created_at','updated_at','isrecommand'
    ];

    //修改器查出省市区
    public function getProvinceAttribute($value){
        return ChinaAreaModel::getName($value);
    }
    public function getCityAttribute($value){
        return ChinaAreaModel::getName($value);
    }
    public function getAreaAttribute($value){
        return ChinaAreaModel::getName($value);
    }




    //获取所有公司
    public function getAllCompany(){
       return self::query()->get(['id', DB::raw('companyname as text')]) ?? [];
    }

    //获取所有公司
    public function getNameById($id){
        return self::whereId($id)->value('companyname');
    }

    public function getNameByName($key){
        return self::where('companyname','like','%'.$key.'%')->get();
    }
    //搜索条件企业
    public function getIdsByName($key){
        return  Company::query()->where('companyname','like','%'.$key.'%')->pluck('id');
    }

    public function getAllById($id){
        return  Company::query()->where('id',$id)->with(['job'=>function($query)use($id){
            $query->where('companyid',$id);
        }])->get();
    }

    public function job(){
        return $this->hasMany('App\Models\Job','companyid','id');
    }

}
